package com.apes.hr.salary.rewardPunish.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.Employee;
import com.apes.hr.base.model.WorkPost;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 功能：奖惩记录单明细
 * @author HuJianlin
 * @create 2018-05-05 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RewardPunishItem.CONST_TABLE_NAME)
public class RewardPunishItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "hr_reward_punish_Item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "奖惩记录")
    @Comment("奖惩明细内码")
    private long id;   //奖惩明细内码

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "reward_punish_id", referencedColumnName = "ID")
    @Comment("奖惩记录单号")
    private RewardPunish rewardPunish; //奖惩记录单号

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("所属公司")
    private PartyRole company;   //所属公司

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Employee_id", referencedColumnName = "ID")
    @Comment("员工")
    private Employee employee;   //员工

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_branch_id", referencedColumnName = "id")
    @Comment("工作部门")
    private Branch workBranch;   //工作部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_post_id", referencedColumnName = "id")
    @Comment("工作岗位")
    private WorkPost workPost;   //工作岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "on_duty_state", referencedColumnName = "id")
    @Comment("在职状态")
    private Enumeration onDutyState; //在职状态(onDutyState)

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "entry_date")
    @Comment("入职日期")
    private Date entryDate;  //入职日期

    @Column(name = "value", nullable = false)
    @Comment("奖励处罚分值")
    private double value = 0;   //奖励处罚分值

    @Column(name = "qty", nullable = false)
    @Comment("次数")
    private int qty = 0;   //次数

    @Column(name = "emp_value_total")
    @Comment("分值合计")
    private double empValueTotal = 0;   //员工已发文的连续12个月行政奖罚分合计

    @Column(name = "amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("奖励少得金额")
    private double amt = 0;    //奖励少得金额


    @Column(name = "afford_loss_amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("承担损失金额")
    private double affordLossAmt;    //承担损失金额

    @Column(name = "cancel_manage_bonus_month", nullable = false)
    @Comment("取消服务管理奖金的月份")
    private int cancelManageBonusMonth;  //取消服务管理奖金的月份

    @Column(name = "manage_bonus_amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("服务管理奖金少得")
    private double manageBonusAmt = 0;    //服务管理奖金少得


    @Column(name = "cancel_year_bonus_month", nullable = false)
    @Comment("取消年终奖的月份")
    private int cancelYearBonusMonth;// 取消年终奖的月份

    @Column(name = "dismiss", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("开除")
    private boolean dismiss;  //开除

    @Column(name = "demotion", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否降职")
    private boolean demotion;//是否降职

    @Column(name = "retain", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否留用察看")
    private boolean retain;//是否留用察看

    @Column(name = "cause",length = 1200)
    @Comment("奖惩事由")
    private String cause;//奖惩事由

    @Column(name = "note",length = 1200)
    @Comment("备注")
    private String note;//备注

    @Column(name = "transfer",length = 120)
    @Comment("调动明细单号")
    private String transfer;//调动明细单号

    @Column(name = "reprieve", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("暂缓执行")
    private boolean reprieve;//暂缓执行

    @Column(name = "no_penalty", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否免罚")
    private boolean noPenalty; //是否免罚

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_on")
    @Comment("调至日期")
    private Date transferOn;//调至日期

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_out")
    @Comment("调离日期")
    private Date transferOut;//调离日期

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "open_day")
    @Comment("调离日期")
    private Date openDay;//门店开业时间

    @Column(name = "create_expense", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否生成费用单")
    private boolean createExpense; //是否生成费用单
}
